import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { RoomUsageApi } from '#/api/spa/room/usage';

import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

import { DICT_SPA_TYPE } from '#/utils/dictSpa';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'roomNumber',
      label: '房间号',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入房间号',
      },
    },
    {
      fieldName: 'billId',
      label: '账单ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入账单ID',
      },
    },
    {
      fieldName: 'usageType',
      label: '使用类型',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
        placeholder: '请选择使用类型',
      },
    },
    {
      fieldName: 'startTime',
      label: '开始时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'endTime',
      label: '结束时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'durationMinutes',
      label: '使用时长(分钟)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入使用时长(分钟)',
      },
    },
    {
      fieldName: 'occupancyCount',
      label: '占用人数',
      component: 'Input',
      componentProps: {
        placeholder: '请输入占用人数',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'operatorId',
      label: '操作员ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入操作员ID',
      },
    },
    {
      fieldName: 'operatorName',
      label: '操作员姓名',
      component: 'Input',
      componentProps: {
        placeholder: '请输入操作员姓名',
      },
    },
    {
      fieldName: 'remarks',
      label: '备注',
      component: 'Input',
      componentProps: {
        placeholder: '请输入备注',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'roomNumber',
      label: '房间号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入房间号',
      },
    },
    {
      fieldName: 'billId',
      label: '账单ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入账单ID',
      },
    },
    {
      fieldName: 'usageType',
      label: '使用类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
        placeholder: '请选择使用类型',
      },
    },
    {
      fieldName: 'startTime',
      label: '开始时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'endTime',
      label: '结束时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'durationMinutes',
      label: '使用时长(分钟)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入使用时长(分钟)',
      },
    },
    {
      fieldName: 'occupancyCount',
      label: '占用人数',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入占用人数',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.HandCardStatus, 'string'),
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'operatorId',
      label: '操作员ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入操作员ID',
      },
    },
    {
      fieldName: 'operatorName',
      label: '操作员姓名',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入操作员姓名',
      },
    },
    {
      fieldName: 'remarks',
      label: '备注',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入备注',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<RoomUsageApi.RoomUsage>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'roomNumber',
      title: '房间号',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'billId',
      title: '账单ID',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'usageType',
      title: '使用类型',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'startTime',
      title: '开始时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'endTime',
      title: '结束时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'durationMinutes',
      title: '使用时长(分钟)',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'occupancyCount',
      title: '占用人数',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'status',
      title: '状态',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'operatorId',
      title: '操作员ID',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'operatorName',
      title: '操作员姓名',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'remarks',
      title: '备注',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
